package com.daxia.wxpay.service;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;

import com.daxia.ogmall.common.Logs;
import com.daxia.wxpay.common.Configure;
import com.daxia.wxpay.common.HttpsRequestNoSSL;
import com.daxia.wxpay.protocol.pay_protocol.ScanPayReqData;
import com.daxia.wxpay.protocol.pay_protocol.UnifiedOrderReqData;

/**
 * User: rizenguo
 * Date: 2014/10/29
 * Time: 16:03
 */
public class UnifiedOrderService extends BaseService{

    public UnifiedOrderService() throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        super(Configure.unifiedorder_api);
    }

    /**
     * 请求支付服务
     * @param scanPayReqData 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    public String request(ScanPayReqData scanPayReqData) throws Exception {

        //--------------------------------------------------------------------
        //发送HTTPS的Post请求到API地址
        //--------------------------------------------------------------------
        String responseString = sendPost(scanPayReqData);

        return responseString;
    }
    
    public static void main(String[] args) throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException, IllegalAccessException, InstantiationException, ClassNotFoundException {
        String body = "Ipad mini  16G  白色";
        String attach = "说明";
        String outTradeNo = "123";
        int totalFee = 1;
        String spBillCreateIP = "8.8.8.8";
                
        String appid = "wx3bb22e6f66087555";
        String merchantId = "1267043101";
        String key = "56CA17F1D2A949D4B907E6F67D10432C";
        UnifiedOrderReqData reqData = new UnifiedOrderReqData(appid, merchantId, key, body, attach, outTradeNo, totalFee, spBillCreateIP, Configure.notify_url);
        UnifiedOrderService service = new UnifiedOrderService();
        service.setServiceRequest(new HttpsRequestNoSSL());
        String xml = service.sendPost(reqData);
        Logs.COMMON.debug("xml: " + xml); 
    }
}
